<?php

class Validate
{
    /**
     * Проверка email
     * @param string $email
     */
    public static function email($email)
    {
        $pattern = '/^[a-z0-9][a-z0-9_\.\-]{1,}\@[a-z0-9]([a-z0-9\-\_]+\.)+[a-z]{2,4}$/isu';
        
        return preg_match($pattern, $email);
    }
    
    /**
     * Проверка пароля
     * @param string $password
     */
    public static function password($password)
    {
        return mb_strlen($password, 'utf-8') >= 3 && mb_strlen($password, 'utf-8') <= 32;
    }
    
    /**
     * Проверка url`a
     * @param $url
     */
    public static function url($url)
    {
        $pattern = '/^(https?:\/\/)?(www\.)?[a-z0-9\-\._]{2,}\.[a-z]{2,4}\/?([a-z0-9\-\._\/]{1,})?(\?.*)?$/iu';
        return preg_match($pattern, $url, $array);
    }
    
    /**
     * Проверка rss-ленты на наличие необходимых узлов
     * @param string $rss_path
     */
    public static function rssFeed($rss_path)
    {
        libxml_use_internal_errors(true);
        var_dump($rss_path);
        $domXml = new DOMDocument();

        if (false === $domXml->load($rss_path)) {
            return false;
        }
        
        if (false === $domXml->schemaValidate(APP_ROOT . '/other/rss.xsd')) {
            var_dump(libxml_get_errors());
            return false;
//            throw new DataException(CONST_DATA_EXCEPTION_ERROR_WRONG_QUESTION_XML.'::'.htmlspecialchars(var_export(array($xml, libxml_get_errors()), true)), __CLASS__, CONST_DATA_EXCEPTION_CODE_WRONG_QUESTION_XML);
        }
        
        libxml_use_internal_errors(false);
        
        return true;
    }
}